package cn.itcast.crm.service.imp;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.itcast.crm.dao.CustomerRepository;
import cn.itcast.crm.domain.Customer;
import cn.itcast.crm.service.ICustomerService;
import oracle.net.aso.s;

@Service
@Transactional
public class CustomerServiceImp implements ICustomerService {
	@Autowired
	CustomerRepository customerRepository;

	@Override
	public List<Customer> findNoAssociationCustomers() {
		// TODO Auto-generated method stub
		return customerRepository.findByFixedAreaIdIsNull();
	}

	@Override
	public List<Customer> findHasAssociationFixedAreaCustomers(String fixedAreaId) {
		// TODO Auto-generated method stub
		
		return customerRepository.findByFixedAreaId(fixedAreaId);
	}

	@Override
	public void associationCustomersToFixedArea(String customerIdStr,String delcustomerIdStr, String fixedAreaId) {
		// TODO Auto-generated method stub
		String[] split = customerIdStr.split(",");
		String[] split2 = delcustomerIdStr.split(",");
		System.out.println(customerIdStr+"-----关联");
		System.out.println("id==========="+fixedAreaId);
		System.out.println(delcustomerIdStr+"-----未关联");
		for (String a : split) {
			Integer id1=Integer.parseInt(a);
			System.out.println("关联"+a);
			customerRepository.associationFixArea(fixedAreaId,id1);
		}
	
		for (String b : split2) {
			Integer id2=Integer.parseInt(b);
			System.out.println("未关联"+b);

			customerRepository.delassociationFixArea(id2);
		}
		
	}

	@Override
	public void regist(Customer customer) {
		// TODO Auto-generated method stub
		customerRepository.save(customer);
	}

	@Override
	public Customer findByTelephone(String telephone) {
		// TODO Auto-generated method stub
		return customerRepository.findByTelephone(telephone);
	}

	@Override
	public void updateType(String telephone) {
		// TODO Auto-generated method stub
		customerRepository.updateType(telephone);
		
	}

}
